#include <bits/stdc++.h>
using namespace std;
const int N = 2e3+5, M = 1e7+5;

// #define dbg(x) fprintf(stderr, "%s -> %d\n", #x, x)
#define dbg(x)

int n, m;
vector<pair<int, int> > G[N];

int dist[N];
namespace spfa {
    int q[M], st, ed;
    int count[N];
    bool in[N];
    
    inline void inc(int &x)
    {
        ++x;
        if (x == M) x = 0;
    }

    
    bool go(int s, int dist[]) {
        memset(dist, 0x3f3f3f3f, sizeof(int) * (n + 1));
        memset(in, 0, sizeof(bool) * (n + 1));
        memset(count, 0, sizeof(int) * (n + 1));
        st = ed = 0;
        dist[s] = 0;
        in[s] = 1;
        q[ed] = s; inc(ed);
        dbg(st);
        dbg(ed);

        while (st < ed) {
            int now = q[st]; inc(st);
            count[now]++; in[now] = false;
            for (const auto &p : G[now])
            {
                int v = p.first, cost = p.second;
                dbg(v);
                if (dist[now] + cost < dist[v])
                {
                    // printf("%d->%d\n", now, v);
                    dist[v] = dist[now] + cost;
                    if (!in[v])
                    {
                        in[v] = true;
                        ++count[v];
                        if (count[v] > n) return true;
                        q[ed] = v; inc(ed);
                    }
                }
            }
        }

        return false;
    }
    
}


int main(int argc, char const *argv[])
{
    int t;
    scanf("%d", &t);
    for (int kk=0; kk<t; ++kk) {
        scanf("%d%d", &n, &m);
        for (int i=1; i<=n; ++i)
            G[i].clear();
        for (int i=1; i<=m; ++i) {
            int u, v, w;
            scanf("%d%d%d", &u, &v, &w);
            dbg(u); dbg(v); dbg(w);
            G[u].emplace_back(v, w);
            if (w >= 0) G[v].emplace_back(u, w);
        }

        bool ans = spfa::go(1, dist);

        // for (int i=1; i<=n; ++i)
        //     printf("%d %d\n", i, dist[i]);
        if (ans) puts("YE5");
        else puts("N0");
    }
    return 0;
}
